package com.ibm.parse.dao;

import java.util.List;
import java.util.Map;
import net.sf.json.JSONObject;
import org.springframework.jdbc.core.JdbcTemplate;
/**
 * 手机银行词义解析dao
 * @author lisheng
 */
public class NJBankParseDAO {
	private JdbcTemplate jdbcTemplate;

	public JdbcTemplate getJdbcTemplate() {
		return this.jdbcTemplate;
	}

	public void setJdbcTemplate(JdbcTemplate jdbcTemplate) {
		this.jdbcTemplate = jdbcTemplate;
	}

	public List<Map<String, Object>> queryMenuKeywordList() {
		String sql = "SELECT MENU_NAME FROM MENU_KEYWORD";
		return this.jdbcTemplate.queryForList(sql);
	}

	public Map<String, Object> queryMenuKeyword() {
		String sql = "SELECT MENU_NAME FROM MENU_KEYWORD";
		Map map = this.jdbcTemplate.queryForMap(sql);
		map.put("menuName", map.get("MENU_NAME"));
		return map;
	}

	public List<Map<String, Object>> queryMenuIdentifierList() {
		String sql = "SELECT MENU_NAME menuName,IDENTIFIER identifier,MENU_ID menuId FROM MENU_IDENTIFIER";
		return this.jdbcTemplate.queryForList(sql);
	}

	public int update(String keywords) {
		String sql = "update MENU_KEYWORD set MENU_NAME=? ";

		JSONObject jo = JSONObject.fromObject(keywords);
		return this.jdbcTemplate.update(
				sql,
				new Object[] { jo.get("menuName") });
	}
	
	//测试数据查询
	public List<Map<String, Object>> queryOneDescribeList() {
		String sql = "select id,one_describe oneDescribe  from analysis_test";
		return this.jdbcTemplate.queryForList(sql);
	}
	
	public int updateTest(Map map) {
		String sql = "update analysis_test a set MENU_NAME='"+map.get("menuName")+"' , KEY_WORDS= '"+map.get("keyword")+"' where id='"+map.get("id")+"'";
		return this.jdbcTemplate.update(sql);
	}
	
	//将解析过的数据插入到日志表
	public void insertAnalysisLog(Map map){
		String sql =  "insert into analysislog a (a.id,a.one_describe,a.key_words,a.menu_name) values("
				+ "analysisseq.nextval,"
				+ "'"+map.get("oneDescribe")+"',"
				+ "'"+map.get("keywords")+"',"
				+ "'"+map.get("menuName")+"')";
		this.jdbcTemplate.update(sql);
	}
}